package com.client.clovece;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.util.Observable;
import java.util.Observer;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;


public class MainMenu extends JFrame implements ActionListener, MyObserver{
	
	JButton netb, locb, endb;
	OnlineMenu onmenu;
	LocalMenu lomenu;

	public MainMenu(){
		netb = new JButton("Sitova hra");
	    locb = new JButton("Lokalni hra");
	    endb = new JButton("Konec");
		Container c = getContentPane();
		JPanel ctrls = new JPanel();
	    ctrls.setLayout( new BoxLayout(ctrls, BoxLayout.Y_AXIS));
	    
	    setGui();
	    
	    ctrls.add(netb);
	    ctrls.add(locb);
	    ctrls.add(endb);
	    
	    c.add(ctrls);
	    setSize(640, 480);
	    setDefaultCloseOperation(EXIT_ON_CLOSE);
		setResizable(false);
	    setVisible(true);
	}

	private void setGui(){
		Dimension d = new Dimension(270,20);
		
		netb.setAlignmentX(Component.CENTER_ALIGNMENT);
		netb.addActionListener(this);
		netb.setMaximumSize(d);
	    locb.setAlignmentX(Component.CENTER_ALIGNMENT);
	    locb.addActionListener(this);
	    locb.setMaximumSize(d);
	    endb.setAlignmentX(Component.CENTER_ALIGNMENT);
	    endb.addActionListener(this);
	    endb.setMaximumSize(d);
	}
	
	@Override
	public void actionPerformed(ActionEvent e){
		Object o = e.getSource();
		Point p = getLocation();
		if(o == netb){
			onmenu = new OnlineMenu(this, p);
			setVisible(false);
		}else if(o == locb){
			lomenu = new LocalMenu(this, p);
			setVisible(false);
		}
		else if(o == endb){
			System.exit(0);
		}
	}

	@Override
	public void update(String text) {
		if(text == "setVisible"){
			setVisible(true);
		}
	}

	@Override
	public void update(String text, Point p) {
		if(text == "setVisible"){
			setLocation(p);
			setVisible(true);
		}
	}

}
